package com.sale.system.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.dev33.satoken.util.SaResult;
import com.sale.common.core.domain.R;
import com.sale.common.core.web.controller.BaseController;
import com.sale.common.log.annotation.Log;
import com.sale.common.log.enums.BusinessType;
import com.sale.common.mybatis.core.page.PageQuery;
import com.sale.common.mybatis.core.page.TableDataInfo;
import com.sale.system.domain.PullDown;
import com.sale.system.domain.SysFields;
import com.sale.system.service.ISysFieldsService;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @Description 表字段获取
 * @Date 23-06-13
 * @Author hl
 **/
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/fields")
public class SysFieldsController extends BaseController {

    private final ISysFieldsService sysFieldsService;

    /**
     * 查询集合
     */
    //@SaCheckPermission("businessConfig:customTable:list")
    @GetMapping("/list")
    public TableDataInfo<SysFields> list(SysFields sysFields, PageQuery pageQuery) {
        return sysFieldsService.selectSysColumn(sysFields, pageQuery);
    }

    /**
     * 新增表头
     */
    //@SaCheckPermission("businessConfig:customTable:add")
    @Log(title = "自定义表头", businessType = BusinessType.INSERT)
    @PostMapping
    public R<Void> add(@Validated @RequestBody SysFields fields) {
        return toAjax(sysFieldsService.insertFields(fields));
    }

    /**
     * 修改自定义表头
     */
    //@SaCheckPermission("businessConfig:customTable:edit")
    @Log(title = "自定义表头", businessType = BusinessType.UPDATE)
    @PutMapping
    public R<Void> edit(@Validated @RequestBody SysFields fields) {
        return toAjax(sysFieldsService.updateFields(fields));
    }

    /**
     * 删除表头
     *
     * @param fieldsId
     */
    //@SaCheckPermission("businessConfig:customTable:remove")
    @Log(title = "自定义表头", businessType = BusinessType.DELETE)
    @DeleteMapping("/{fieldsId}")
    public R<Void> remove(@PathVariable long fieldsId) {
        return toAjax(sysFieldsService.deleteFieldsByIds(fieldsId));
    }

    /**
     * 查询
     */
    //@SaCheckPermission("businessConfig:customTable:query")
    @GetMapping("/path")
    public SaResult getInfo2(String path) {
        return SaResult.data(sysFieldsService.selectSysFields(path));
    }

    /**
     * 查询表头
     */
    @GetMapping("/getInfo")
    public R<List<PullDown>> getInfo(String path) {
        List<PullDown> list = sysFieldsService.selectSysFields(path);
        return R.ok(list);
    }

    /**
     * 根据菜单路由查询动态表头集合转驼峰
     */
    @GetMapping("/getCaseList")
    public Map<String, String> getCaseList(String path) {
        return sysFieldsService.getCaseList(path);
    }


}
